﻿var xmlData = null;
var data = null;
var browser_type = null;
var type_MSIE = 'MSIE';
var type_Firefox = 'Firefox';

browser_type = window.navigator.userAgent.indexOf('MSIE') != -1 ? type_MSIE : window.navigator.userAgent.indexOf('Firefox') != -1 ? type_Firefox : 'Unsupported';

function LoadData()
{    
    xmlData = browser_type == type_MSIE ? xmlData=new ActiveXObject("Microsoft.XMLDOM") : document.implementation.createDocument("","",null);    
    xmlData.async="false";
    xmlData.load("test_data.xml");  
    
    LoadPushPins();   
}

function ScrollToPushPin(e)
{    
    var name = e.elementID;
    if(name != null)
    { 
        var shape = map.GetShapeByID(e.elementID);
        Effect.ScrollContainerTo($('have_list'),$('h'+shape.Id));        
    }    
}

function LoadPushPins()
{   
    
    map.AttachEvent("onmouseover", ScrollToPushPin);                    
    
    var users = xmlData.getElementsByTagName("user");                    
    
    for(var i = 1; i < 20; i++)
    {        
        var userid = users.item(i).getElementsByTagName("id")[0].firstChild.nodeValue;
        var username = users.item(i).getElementsByTagName("username")[0].firstChild.nodeValue;
        var icon = users.item(i).getElementsByTagName("icon")[0].firstChild.nodeValue;
        var lat = users.item(i).getElementsByTagName("lat")[0].firstChild.nodeValue;
        var lon = users.item(i).getElementsByTagName("lon")[0].firstChild.nodeValue;                
        var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(lat, lon));
        
        shape.SetCustomIcon(icon);
        shape.SetTitle('<h2>' + username + '</h2>');       
        shape.SetDescription('This user has the id of ' + userid);       
        shape.Id = i; 

        map.AddShape(shape);
    }
    return true;
}

Effect.ScrollContainerTo = function(container, element){
  if(container == null || element == null) return false; 
  var originalScrollTop = $(container).scrollTop;  
  var finalScrollTop = $(element).cumulativeOffset()[1] - $(container).cumulativeOffset()[1];
  var max = $(container).height;   
  
  return new Effect.Tween(container,
    originalScrollTop,
    finalScrollTop > max ? max : finalScrollTop,
    function(p){ container.scrollTop = p.round()});
};

